import 'package:event_bus/event_bus.dart';
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'package:yueyin/global/global_theme.dart';
import 'package:yueyin/global/j_push.dart';
import 'package:yueyin/global/provider.dart';
import 'package:yueyin/global/yin.dart';
import 'package:yueyin/routes/route.dart';
import 'package:yueyin/service/theme_service.dart';

final GlobalKey<NavigatorState> globalKey = GlobalKey<NavigatorState>();

final EventBus bus = EventBus();

void main() async {
  //初始化
  WidgetsFlutterBinding.ensureInitialized();

  //初始化 preference
  SharedPreferences sp = await SharedPreferences.getInstance();
  Yin().initPref(sp);

  runApp(withProvidersApp(MyApp()));
}

class MyApp extends StatefulWidget {
  const MyApp({Key? key}) : super(key: key);

  @override
  _MyAppState createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  final YuePush push = YuePush.instance;

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: '越音',
      navigatorKey: globalKey,
      debugShowCheckedModeBanner: false,
      routes: routes,
      theme: ThemeData.light().copyWith(
          primaryColor: themeColors[Provider.of<ThemeService>(context).color]),
    );
  }
}
